<pngx-page-header title="Consumption Templates" i18n-title>
  <button type="button" class="btn btn-sm btn-outline-primary ms-4" (click)="editTemplate()" *pngxIfPermissions="{ action: PermissionAction.Add, type: PermissionType.ConsumptionTemplate }">
    <svg class="sidebaricon me-1" fill="currentColor">
      <use xlink:href="assets/bootstrap-icons.svg#plus-circle" />
    </svg>
    <ng-container i18n>Add Template</ng-container>
  </button>
</pngx-page-header>

<ul class="list-group">

  <li class="list-group-item">
    <div class="row">
      <div class="col" i18n>Name</div>
      <div class="col" i18n>Sort order</div>
      <div class="col" i18n>Document Sources</div>
      <div class="col" i18n>Actions</div>
    </div>
  </li>

  @for (template of templates; track template) {
    <li class="list-group-item">
      <div class="row">
        <div class="col d-flex align-items-center"><button class="btn btn-link p-0" type="button" (click)="editTemplate(template)" [disabled]="!permissionsService.currentUserCan(PermissionAction.Change, PermissionType.ConsumptionTemplate)">{{template.name}}</button></div>
        <div class="col d-flex align-items-center"><code>{{template.order}}</code></div>
        <div class="col d-flex align-items-center">{{getSourceList(template)}}</div>
        <div class="col">
          <div class="btn-group">
            <button *pngxIfPermissions="{ action: PermissionAction.Change, type: PermissionType.ConsumptionTemplate }" class="btn btn-sm btn-outline-secondary" type="button" (click)="editTemplate(template)">
              <svg class="buttonicon-sm" fill="currentColor">
                <use xlink:href="assets/bootstrap-icons.svg#pencil" />
                </svg>&nbsp;<ng-container i18n>Edit</ng-container>
              </button>
              <button *pngxIfPermissions="{ action: PermissionAction.Delete, type: PermissionType.ConsumptionTemplate }" class="btn btn-sm btn-outline-danger" type="button" (click)="deleteTemplate(template)">
                <svg class="buttonicon-sm" fill="currentColor">
                  <use xlink:href="assets/bootstrap-icons.svg#trash" />
                  </svg>&nbsp;<ng-container i18n>Delete</ng-container>
                </button>
              </div>
            </div>
          </div>
        </li>
      }
      @if (templates.length === 0) {
        <li class="list-group-item" i18n>No templates defined.</li>
      }
    </ul>
